<template>
  <div class="publish-notice">
    <h2>发布通知</h2>
    <el-form :model="noticeForm" label-width="80px" class="form">
      <el-form-item label="标题">
        <el-input v-model="noticeForm.title" placeholder="请输入通知标题"></el-input>
      </el-form-item>
      <el-form-item label="内容">
        <el-input
            type="textarea"
            v-model="noticeForm.content"
            placeholder="请输入通知内容"
            rows="6"
        ></el-input>
      </el-form-item>
      <el-form-item>
        <div class="form-footer">
          <el-button type="primary" @click="submitNotice">发布</el-button>
        </div>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import axios from 'axios';
import {BASE_URL} from "@/config";

export default {
  data() {
    return {
      noticeForm: {
        title: '',
        content: ''
      }
    };
  },
  methods: {
    submitNotice() {
      if (!this.noticeForm.title || !this.noticeForm.content) {
        this.$message.error('标题和内容不能为空');
        return;
      }

      axios.post(`${BASE_URL}/notifications/create`, this.noticeForm)
          .then(response => {
            this.$message.success(response.data.message);
          })
          .catch(error => {
            this.$message.error('通知发布失败');
          });
    }
  }
};
</script>

<style scoped>
.publish-notice {
  max-width: 600px; /* 增加宽度 */
  margin: 50px auto; /* 居中 */
  padding: 20px;
  background: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.1);
}

h2 {
  text-align: center;
  margin-bottom: 20px;
}

.form {
  width: 100%; /* 使表单宽度填满 */
}

.form-footer {
  text-align: center;
  margin-top: 20px;
}

.el-form-item {
  margin-bottom: 20px;
}
</style>
